package com.hr.modules.person.controller;

import com.hr.common.annotation.SysLog;
import com.hr.common.utils.DateUtils;
import com.hr.common.utils.PageUtils;
import com.hr.common.utils.R;
import com.hr.common.validator.ValidatorUtils;
import com.hr.modules.person.entity.InterviewPlanEntity;
import com.hr.modules.person.service.InterviewPlanService;
import com.hr.modules.sys.controller.AbstractController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;


/**
 * 面试管理
 *
 * @author 553039957@qq.com
 */
@RestController
@RequestMapping("/person/interview")
public class InterviewPlanController extends AbstractController {
    @Autowired
    private InterviewPlanService interviewPlanService;

    /**
     * 所有面试列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("person:apply:list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = interviewPlanService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 面试信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("person:apply:info")
    @ResponseBody
    public R info(@PathVariable("id") Long id) {
        InterviewPlanEntity interview = interviewPlanService.getById(id);

        return R.ok().put("interview", interview);
    }

    /**
     * 保存面试
     */
    @SysLog("保存面试")
    @RequestMapping("/save")
    @RequiresPermissions("person:apply:save")
    public R save(@RequestBody InterviewPlanEntity apply) {
        ValidatorUtils.validateEntity(apply);
        apply.setCreateTime(DateUtils.currentTimeFormat());
        interviewPlanService.save(apply);

        return R.ok();
    }

    /**
     * 修改面试
     */
    @SysLog("修改面试")
    @RequestMapping("/update")
    @RequiresPermissions("person:apply:update")
    public R update(@RequestBody InterviewPlanEntity apply) {
        ValidatorUtils.validateEntity(apply);
        interviewPlanService.update(apply);

        return R.ok();
    }

    /**
     * 删除面试
     */
    @SysLog("删除面试")
    @RequestMapping("/delete")
    @RequiresPermissions("person:apply:delete")
    public R delete(@RequestBody Long[] ids) {
        interviewPlanService.deleteBatch(ids);
        return R.ok();
    }
}
